<?php

// [ Hook类 ]

namespace core;
use core\Config;

class Hook
{
    public static function listen($tag, &$params = null)
    {
        $hooks = Config::get("hook.$tag");
        if ( !empty($hooks) ) {
            $results = [];
            foreach ($hooks as $key => $hook) {
                $results[$key] = self::exec($hook, $params);
                if (false === $results[$key]) break;
            }
            return $results;
        }
    }

    public static function exec($hook, &$params = null)
    {
        return call_user_func_array([$hook,'run'], [&$params]);
    }
}
